/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package wf.model;

import bc.swing.pfrm.Model;
import bc.swing.pfrm.ano.PageDef;
import bc.swing.pfrm.layouts.FormLayout;
import com.j256.ormlite.field.DatabaseField;
import com.j256.ormlite.table.DatabaseTable;

/**
 *
 * @author bennyl
 */
@DatabaseTable(tableName = "users")
public class User extends Model{
    public static final String NAME = "name";
    public static final String PASS_HASH = "passHash";
    public static final String ROLE = "role";
    
    @DatabaseField(id=true)
    private String name;
    @DatabaseField(canBeNull= false)
    private String passHash;
    @DatabaseField(columnName="role")
    private Integer role;

    /**
     * for ormlite.. 
     */
    public User() {
        this.role = User.Role.USER.getNum();
    }

    public User(String name, String passHash, int role) {
        this.name = name;
        this.passHash = passHash;
        this.role = role;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getPassHash() {
        return passHash;
    }

    public void setPassHash(String passHash) {
        this.passHash = passHash;
    }

    public Integer getRole() {
        return role;
    }

    public void setRole(Integer role) {
        this.role = role;
    }

    public boolean isAdmin() {
        return getRole() == Role.ADMIN.getNum();
    }

    public static enum Role{
        ADMIN(1),
        USER(0);
        
        int num;

        private Role(int num) {
            this.num = num;
        }

        public int getNum() {
            return num;
        }
    }
    
}
